package com.knight.sychronized.node;

import java.util.concurrent.locks.AbstractQueuedSynchronizer;

public class KnightNodeTester {
    private static KnightNode head;

    /**
     * Tail of the wait queue, lazily initialized.  Modified only via
     * method enq to add new wait node.
     */
    private static KnightNode tail;

    public static void main(String[] args) {
        KnightNode head = new KnightNode();
        KnightNodeTester.head = head;
        if (head.next == null) {
            KnightNode next1 = new KnightNode();
            next1.thread = new Thread("t1");
            head.next = next1;
            next1.prev = head;

            if (next1.next == null) {
                KnightNode next2 = new KnightNode();
                next2.thread = new Thread("t2");
                next1.next = next2;
                next2.prev = next1;
                if (next2.next == null) {
                    KnightNode next3 = new KnightNode();
                    next3.thread = new Thread("t3");
                    next2.next = next3;
                    next3.prev = next2;

                    KnightNodeTester.tail = next3;
                }
            }


        }

        KnightNode node = head.next;
        KnightNode s = null;
        for (KnightNode t = tail; t != null && t != node; t = t.prev) {
            s = t;

        }

        System.out.println(head);
        System.out.println(s);
    }
}
